<template>
  <el-card class="overall-card">
    <div>
      <!-- 页面标题 -->
      <h2>分析详情</h2>

      <!-- 图表部分 -->
      <div class="chart-section">
        <el-card class="chart-card">
          <h3>难度系数分析</h3>
          <div id="difficulty-chart" class="chart-container"></div>
        </el-card>
        <el-card class="chart-card">
          <h3>题型分值占比分析</h3>
          <div id="question-type-chart" class="chart-container"></div>
        </el-card>
      </div>

      <!-- 题目详情 -->
      <el-card class="detail-section">
        <h3>题目详情分布</h3>
        <div class="question-list">
          <el-row :gutter="20">
            <el-col :span="8" v-for="(question, index) in questionDetails" :key="index">
              <el-tag type="info">
                {{ index + 1 }}: {{ question.title }} ({{ question.score }}分)
              </el-tag>
            </el-col>
          </el-row>
        </div>
      </el-card>
    </div>
  </el-card>
</template>

<script>
import * as echarts from "echarts";
import { onMounted, ref } from "vue";

export default {
  setup() {
    const difficultyData = ref({
      labels: ["非常容易", "比较容易", "常规", "较难", "非常难"],
      values: [60, 40, 55, 20, 10],
    });
    const questionTypeData = ref([
      { name: "单选题", value: 30 },
      { name: "多选题", value: 30 },
      { name: "判断题", value: 20 },
      { name: "简答题", value: 20 },
    ]);
    const questionDetails = ref([
      { title: "PS的用法详解", score: 2 },
      { title: "PS的用法详解", score: 2 },
      { title: "PS的用法详解", score: 2 },
      { title: "PS的用法详解", score: 2 },
      { title: "PS的用法详解", score: 2 },
      { title: "PS的用法详解", score: 2 },
      { title: "PS的用法详解", score: 2 },
    ]);

    const initCharts = () => {
      // 难度系数图表
      const difficultyChart = echarts.init(
        document.getElementById("difficulty-chart")
      );
      difficultyChart.setOption({
        xAxis: {
          type: "category",
          data: difficultyData.value.labels,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: difficultyData.value.values,
            type: "bar",
            color: "#42b983",
          },
        ],
      });

      // 题型分值占比图表
      const questionTypeChart = echarts.init(
        document.getElementById("question-type-chart")
      );
      questionTypeChart.setOption({
        tooltip: {
          trigger: "item",
        },
        legend: {
          bottom: "0%",
        },
        series: [
          {
            name: "题型分析",
            type: "pie",
            radius: "50%",
            data: questionTypeData.value.map(({ name, value }) => ({
              name,
              value,
            })),
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
    };

    onMounted(() => {
      initCharts();
    });

    return {
      difficultyData,
      questionTypeData,
      questionDetails,
    };
  },
};
</script>

<style scoped>
.overall-card {
  padding: 20px;
}

.chart-section {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
}

.chart-card {
  flex: 1;
}

.chart-container {
  width: 100%;
  height: 400px;
}

.detail-section {
  margin-top: 30px;
}

.question-list {
  margin-top: 20px;
}

h2,
h3 {
  text-align: center;
  margin-bottom: 20px;
}
</style>
